﻿Imports MySoft.Map.Data
Imports MyWorkflow
Imports MySoft.Map.Workflow.Business
Imports Mysoft.Map.Application.Controls 

Partial Public Class WF_ProcessCommonModule
    Inherits Mysoft.Map.Application.Security.AppPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim strSQL, UserGUID As String
            UserGUID = Session("userGUID").ToString()
            Dim applications As String = Mysoft.Map.Application.Security.VerifyApplication.GetLicenseApplicationString()

            If Not Mysoft.Map.Application.Security.User.IsAdmin(UserGUID) Then
                Dim buGUIDs As String = UserRights.GetUserLocalBU(UserGUID)
                Dim buCodes As String = UserRights.GetUserLocalBU(UserGUID, "code")
                buCodes = buCodes.Replace("','", ".,").Replace("'", "") + "."

                strSQL = "SELECT   a.ProcessGUID as 'GUID'," + _
                              "  a.ProcessName as 'Name'," + _
                              " CASE WHEN c.DataGUID is NULL THEN a.ProcessName ELSE '<font color=""#C3C3B4""> '+a.ProcessName+'</font>' end AS showHTML," + _
                              " CASE WHEN c.DataGUID is NULL THEN 0 ELSE 1 end AS ishave, " + _
                              " c.DataGUID ,c.OrderID" + _
                             " FROM (select ProcessGUID , ProcessName , ProcessKindGUID ,DocumentType ,Application " + _
                              " from myWorkflowProcessModule " + _
                              " where IsActive=1 and BUGUID in (" + _
                              " select BUGUID from myBusinessUnit where charindex(HierarchyCode + '.','" & buCodes & "')=1) " + _
                              " and CanChildBU=1 " + _
                              " union " + _
                             " select ProcessGUID,ProcessName, ProcessKindGUID ,DocumentType,Application " + _
                             " from myWorkflowProcessModule " + _
                             " where IsActive=1 and BUGUID in (" + buGUIDs + ") " + _
                             " ) a " + _
                            " LEFT JOIN myworkflowprocesskind b on a.processkindguid = b.processkindguid" + _
                            " LEFT JOIN myWorkflowCommonModule c ON a.ProcessGUID=c.ProcessGUID AND c.UserGUID='" & UserGUID & "'" + _
                            " WHERE ( IsNull(a.Application,'') = '' OR Application IN ('" & applications.Replace(",", "','") & "') )" & _
                            " Order by a.processname"
            Else
                'BUG:增加管理员的取值SQL panhh 2009-04-20
                strSQL = "SELECT   a.ProcessGUID as 'GUID'," + _
                              "  a.ProcessName as 'Name'," + _
                              " CASE WHEN c.DataGUID is NULL THEN a.ProcessName ELSE '<font color=""#C3C3B4""> '+a.ProcessName+'</font>' end AS showHTML," + _
                              " CASE WHEN c.DataGUID is NULL THEN 0 ELSE 1 end AS ishave, " + _
                              " c.DataGUID ,c.OrderID" + _
                             " FROM myWorkflowProcessModule a " + _
                            " LEFT JOIN myworkflowprocesskind b on a.processkindguid = b.processkindguid" + _
                            " LEFT JOIN myWorkflowCommonModule c ON a.ProcessGUID=c.ProcessGUID AND c.UserGUID='" & UserGUID & "'" + _
                            " WHERE a.IsActive = 1 AND ( IsNull(a.Application,'') = '' OR Application IN ('" & applications.Replace(",", "','") & "') )" & _
                            " Order by a.processname"
            End If


            rep1.ConnectionString = MyDB.GetSqlConnectionString
            rep1.BindMode = 0
            rep1.SQL = strSQL
            rep1.DataBind()

            strSQL = "SELECT a.ProcessGUID as 'GUID', a.ProcessName AS 'name' FROM myWorkflowCommonModule AS c INNER JOIN myWorkflowProcessModule AS a ON c.ProcessGUID=a.ProcessGUID WHERE c.UserGUID='" & UserGUID & "' ORDER by c.OrderID"
            rep2.ConnectionString = MyDB.GetSqlConnectionString
            rep2.BindMode = 0
            rep2.SQL = strSQL
            rep2.DataBind()
        End If
    End Sub

End Class